<?php
/* @var $this ArtikelController */
/* @var $model Artikel */
/* @var $form CActiveForm */
?>

<hr/>
    <h2>Upload foto</h2>
<hr/>

<form id="upload_foto" enctype="multipart/form-data" method="post">
    
    <input type="file" name="file1" id="file1"/><br/>
    <input type="button" value="upload foto" onclick="uploadFoto1()" />
    <progress id="progressBar" value="0" max="100" style="width: 300px;" ></progress>
    <p id="status"></p>
    <hr/>
</form>
    
    <script type="text/javascript">
        function uploadFoto1(){
            var foto=document.getElementById('file1').files[0];
            
            var formdata=new FormData();
            formdata.append("file1",foto);
            var xmlhttp=new XMLHttpRequest();
            xmlhttp.upload.addEventListener("progress", progressHandler, false);
            xmlhttp.addEventListener("load", completeHandler, false);
            xmlhttp.addEventListener("error", errorHandler, false);
            xmlhttp.addEventListener("abort", abortHandler, false);
            xmlhttp.open("POST", "<?php echo Yii::app()->createUrl("/artikel/file_uploaded_parser") ?>",true);
            xmlhttp.send(formdata);
        }
        
        function progressHandler(evt){
            var percent=(evt.loaded/evt.total*100);
            document.getElementById("status").innerHTML=(percent)+"%";
            document.getElementById("progressBar").value=Math.round(percent);
        }
        
        function completeHandler(evt){
            document.getElementById('status').innerHTML=event.target.responseText;
            document.getElementById('Artikel_fotoUtama').value=document.getElementById('nama_file1').innerHTML;
        }
        
        function errorHandler(evt){
            document.getElementById('status').innerHTML="Upload Gagal";
        }
        
        function abortHandler(evt){
            document.getElementById('status').innerHTML="Upload Batal";
        }
    </script>

<div class="form">
    
    

    
    
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'artikel-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Kolom dengan <span class="required">*</span> harus diisi.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'judul'); ?>
		<?php echo $form->textField($model,'judul',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'judul'); ?>
	</div>

        <div class="row">
		<?php echo $form->labelEx($model,'isi'); ?>
		<?php $this->widget('application.extensions.cleditor.ECLEditor', array(
			'model'=>$model,
			'attribute'=>'isi',
			'options'=>array(
				'width'=>'700',
				'height'=>250,
				'useCSS'=>true,
			),
			'value'=>$model->isi,));
		?>
		<?php echo $form->error($model,'isi'); ?>
	</div>
        
        <?php echo $form->hiddenField($model,'user_id',array('value'=>$model->user_id)); ?>
        <?php echo $form->hiddenField($model,'tanggalPost',array('value'=>$model->tanggalPost)); ?>
        <?php echo $form->hiddenField($model,'fotoUtama',array('value'=>"")); ?>
        
        
        
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->